home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / cstex / disk1 / demo.lzh / DEMO / LIFE.TEX < prev    next >
Encoding:
Text File  |  1989-06-06  |  2.7 KB  |  95 lines

  1. %format plain       % or plaing
  2. % Life in TeX by Tomas Rokicki (rokicki@rocky.stanford.edu) (30 Aug 87)
  3. % Here is an implementation of LIFE in TeX, on a 32 by 32 grid.
  4. % Output goes to the screen; if anyone wants to hack it up to
  5. % send output to a .dvi file in some pretty format, I would be
  6. % interested.  It's a true hack, but an interesting One.
  7. %
  8. % To run, simply run TeX over it, and enter the coordinates of
  9. % the points, one by one.  Enter a -1 for the last x coordinate.
  10. % Try, for instance, 15, 16, 16, 15, 16, 16, 17, 16, 17, 15, -1.
  11.  
  12. \font\a=cmr10 at 11truept
  13. \fontdimen2246\a=0pt
  14. \newcount\p\newcount\q\newcount\x\newcount\y\newcount\t
  15. \newcount\qq\newcount\abase\newcount\bbase\newcount\g
  16. \abase=35\bbase=1158
  17. \p=1
  18. \loop
  19.    \ifnum\p<23
  20.       \fontdimen\p\a=0sp
  21.       \advance\p by1
  22. \repeat
  23. \loop
  24.    \read0 to\xcoord
  25.    \x=\xcoord
  26.    \ifnum\x>-1
  27.       \read0 to\ycoord
  28.       \y=\ycoord
  29.       \multiply\y by 33
  30.       \advance\y by\abase
  31.       \advance\y by\x
  32.       \fontdimen\y\a=5sp
  33. \repeat
  34. \def\yloop{{
  35.    \y=0
  36.    \def\w{}
  37.    \loop
  38.       \t=\fontdimen\p\a
  39.       \ifnum\t>4
  40.          \ifnum\t<8
  41.             \qq=\q
  42.             \advance\qq by-34
  43.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  44.             \advance\qq by1
  45.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  46.             \advance\qq by1
  47.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  48.             \advance\qq by31
  49.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  50.             \advance\qq by1
  51.             \t=\fontdimen\qq\a\advance\t by1\fontdimen\qq\a=\t sp
  52.             \advance\qq by1
  53.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  54.             \advance\qq by31
  55.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  56.             \advance\qq by1
  57.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  58.             \advance\qq by1
  59.             \t=\fontdimen\qq\a\advance\t by2\fontdimen\qq\a=\t sp
  60.             \xdef\w{\w*}
  61.          \else
  62.             \xdef\w{\w.}
  63.          \fi
  64.       \else
  65.          \xdef\w{\w.}
  66.       \fi
  67.       \fontdimen\p\a=0sp
  68.       \global\advance\p by1
  69.       \global\advance\q by1
  70.       \advance\y by1
  71.    \ifnum\y<32\repeat
  72.    \immediate\write0{|\w|}
  73. }}
  74. \def\dogeneration{{
  75.    \global\p=\abase
  76.    \global\q=\bbase
  77.    \immediate\write0{|--------------------------------| Generation \number\g}
  78.    \x=0
  79.    \loop
  80.       \yloop
  81.       \global\advance\p by1
  82.       \global\advance\q by1
  83.       \advance\x by1
  84.    \ifnum\x<32\repeat
  85.    \t=\abase
  86.    \global\abase=\bbase
  87.    \global\bbase=\t
  88. }}
  89. \loop
  90.    \global\advance\g by1
  91.    \dogeneration
  92. \iftrue\repeat
  93. \bye
  94. ə
  95.